/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package exatrez.manager;

import com.google.inject.Inject;
import com.wideplay.warp.persist.Transactional;
import exatrez.dao.SeverityCodeDAO;
import exatrez.model.SeverityCode;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author wan.fairul
 */
public class SeverityManager {

    @Inject
    protected com.google.inject.Provider<Session> sessionProvider;
    @Inject
    private SeverityCodeDAO severityCodeDAO;

    @Transactional
    public void saveOrUpdate(SeverityCode severity) {
        severityCodeDAO.saveOrUpdate(severity);
    }

    @Transactional
    public void deleteSeverity(SeverityCode severity) {
        severityCodeDAO.delete(severity);
    }

    public SeverityCode findSeverityName(String severityName) {
        String query = "SELECT a FROM SeverityCode a WHERE a.severityName = :severityName  ";
        Query q = sessionProvider.get().createQuery(query);
        q.setString("severityName", severityName);
        return (SeverityCode) q.uniqueResult();
    }

    public SeverityCode findNotSeverityName(String severityCodeId,String severityName) {
        String query = "SELECT a FROM SeverityCode a WHERE a.severityCodeId != :severityCodeId and a.severityName = :severityName  ";
        Query q = sessionProvider.get().createQuery(query);
        q.setString("severityCodeId", severityCodeId);
        q.setString("severityName", severityName);
        return (SeverityCode) q.uniqueResult();
    }

    public SeverityCodeDAO getSeverityCodeDAO() {
        return severityCodeDAO;
    }

    public void setSeverityCodeDAO(SeverityCodeDAO severityCodeDAO) {
        this.severityCodeDAO = severityCodeDAO;
    }
}
